package wblog.domain;

import java.sql.Timestamp;

public class Article {

    public long id;
    public String title;
    public String content;
    public Timestamp postDate;
    public String authorId;
    public String tags;
    public int view;
    public int commentCount;

    public User author;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Timestamp getPostDate() {
        return postDate;
    }

    public void setPostDate(Timestamp postDate) {
        this.postDate = postDate;
    }

    public String getAuthorId() {
        return authorId;
    }

    public void setAuthorId(String authorId) {
        this.authorId = authorId;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public String[] getTagList() {
        if (tags == null || (tags = tags.trim()).isEmpty()) {
            return new String[0];
        }
        return tags.split("\\s+");
    }

    public int getView() {
        return view;
    }

    public void setView(int view) {
        this.view = view;
    }

    public int getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(int commentCount) {
        this.commentCount = commentCount;
    }

    public User getAuthor() {
        return author;
    }

    public void setAuthor(User author) {
        this.author = author;
    }

    public String getShortContent(int len) {
        if (content == null) return "";
        if (content.length() <= len) return content;
        return content.substring(0, len) + "...";
    }
}
